package com.servlet.web;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Title: RequestServlet01
 * @Description:
 * @Auther: py
 * @Version: 1.0
 * @create 2023/12/21 14:23
 */
@WebServlet("/req01")
public class RequestServlet01 extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
          // 获取请求行信息
        String method = req.getMethod();  // 请求方式
        String protocol = req.getProtocol(); // 请求协议
        String requestURI = req.getRequestURI();
        StringBuffer requestURL = req.getRequestURL();
        System.out.println(method);  // GET
        System.out.println(protocol); // HTTP/1.1
        System.out.println(requestURI); // /web/req01
        System.out.println(requestURL); // 全路径 协议://ip:port/项目路径

        resp.getWriter().write("响应成功!");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
